﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace baseClass.controls
{
    public partial class emWorkRewardDetail : common.control.baseUserControl
    {
        private System.Windows.Forms.BindingSource myDataSource = null;
        public string myRewardCat = application.Consts.constWorkReward;
        public emWorkRewardDetail()
        {
            InitializeComponent();
            SetMaxLength();
        }

        public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
        {
            this.myDataSource = dataSrc;

            data.baseDS.emWorkRewardDataTable tbl = (data.baseDS.emWorkRewardDataTable)dataSrc.DataSource;
            this.titleEd.DataBindings.Clear();
            this.titleEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.tittleColumn.ColumnName, true));

            this.typeCb.DataBindings.Clear();
            this.typeCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSrc, tbl.typeColumn.ColumnName, true));

            this.issuerEd.DataBindings.Clear();
            this.issuerEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.issueByColumn.ColumnName, true));

            this.decisionNoEd.DataBindings.Clear();
            this.decisionNoEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.decisionNoColumn.ColumnName, true));

            this.onDateEd.DataBindings.Clear();
            this.onDateEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.onDateColumn.ColumnName, true));

            this.descEd.DataBindings.Clear();
            this.descEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.descriptionColumn.ColumnName, true));
        }
        private void SetMaxLength()
        {
            data.baseDS.emWorkRewardDataTable tbl = new data.baseDS.emWorkRewardDataTable();
            titleEd.MaxLength = tbl.tittleColumn.MaxLength;
            decisionNoEd.MaxLength = tbl.decisionNoColumn.MaxLength;
            issuerEd.MaxLength = tbl.issueByColumn.MaxLength;
            descEd.MaxLength = tbl.descriptionColumn.MaxLength;
        }
        public virtual void Init() 
        {
            typeCb.LoadData();
        }

        public virtual bool CheckData()
        {
            if (this.myDataSource.Current == null) return true;
            bool retVal = true;
            ClearNotifyError();
            if (titleEd.Text.Trim() == "")
            {
                NotifyError(titleLbl);
                retVal = false;
            }
            if (issuerEd.Text.Trim() == "")
            {
                NotifyError(issuerLbl);
                retVal = false;
            }
            if (typeCb.myValue == "")
            {
                NotifyError(typeLbl);
                retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            if (myDataSource.Current == null) state = true; 
            titleEd.ReadOnly = state;
            onDateEd.ReadOnly = state;
            typeCb.Enabled = !state;
            decisionNoEd.ReadOnly = state;
            issuerEd.ReadOnly = state;
            descEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            titleEd.Focus();
        }
    }
}
